package com.wlyuan.open.application.listener;

import com.alibaba.excel.util.StringUtils;
import com.wlyuan.core.domain.event.DomainEventListener;
import com.wlyuan.open.domain.client.event.ChangeSecretEvent;
import com.wlyuan.open.domain.qrcode.service.QrCodeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.springframework.stereotype.Service;

/**
 * @author lijing
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class ChangeSecretEventListener implements DomainEventListener<ChangeSecretEvent> {
    private final QrCodeService qrCodeService;

    @Override
    @Subscribe(sticky = true, threadMode = ThreadMode.ASYNC)
    public void handle(ChangeSecretEvent event) {
        logger.info("client重置appSecret通知");
        //删除二维码文件
        if (StringUtils.isNotBlank(event.getQrCodeId())) {
            qrCodeService.remove(event.getQrCodeId());
        }
    }
}
